package lntu.cn;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class MainActivity extends Activity {
    private Button btnLogin;
    private Button btn;

    private EditText name;
    private EditText password;
    private String stuPassword;
    private List<Student> stuList;



    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        btnLogin = (Button) findViewById(R.id.btn_dl);
        btnLogin.setOnClickListener(new MyListener());

        class  MyListener implements View.OnClickListener{
            @Override
            public void onClick(View v) {
                Intent intent=new Intent(MainActivity.this,Login.class);
                startActivity(intent);
            }
        }

        stuList=new ArrayList<Student>();
        Student stu1=new Student("zhangsan","111111");
        Collections.addAll(stuList,stu1);

        Button btnLog=(Button)findViewById(R.id.btn_dl);
        name=(EditText)findViewById(R.id.et_name);
        password=(EditText)findViewById(R.id.et_password);
        //添加配置信息
        btnLog.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String stuname=name.getText().toString();
                Student stu=new Student(stuname,stuPassword);
                if (stuList.contains(stu)){
                    Log.i("RegLog","用户名已存在");
                    Toast.makeText(MainActivity.this,"注册失败",Toast.LENGTH_LONG).show();
                }else{
                    Log.i("RegLog","注册成功");
                    Toast.makeText(MainActivity.this,"注册成功",Toast.LENGTH_LONG).show();
                    stuList.add(stu);

                }
            }
        });

    }

    public void login(View view) {
        Intent intent=new Intent();
        intent.setClass(MainActivity.this,Login.class);
        startActivity(intent);
    }

    private class MyListener implements View.OnClickListener {
        @Override
        public void onClick(View v) {
            Intent intent=new Intent(MainActivity.this,Login.class);
            startActivity(intent);
        }
    }


}
